using System;
using UnityEngine;

public class PlayerState_PrimaryAttack : PlayerState
{
    private int comboCounter;
    private float lastTimeAttacked;
    private float comboWindow = 0.33f;
    
    public PlayerState_PrimaryAttack(Player player, PlayerStateMachine stateMachine, string animBoolName) : base(player, stateMachine, animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        
        
        player.Movement(Vector2.zero);
        if (comboCounter > 2 || Time.time >= lastTimeAttacked + comboWindow)
        {
            comboCounter = 0;
        }
        
        var force = (comboCounter + 1) * 1.5f;
        player.movement.AddForce(player.controller.forward , ForceMode.Impulse);

        Debug.Log(force);
        player.SetAnim("ComboCounter", comboCounter);
    }

    public override void Exit()
    {
        base.Exit();
        player.StartCoroutine(player.BusyFor(0.15f));
        comboCounter++;
        lastTimeAttacked = Time.time;
    }

    public override void Update()
    {
        base.Update();
        if (triggerCalled)
        {
            stateMachine.ChangeState(player.idleState);
        }
    }
}
